<template>
	<view class="app_main">
		<NavTabbar activeTab="user"></NavTabbar>
		<view class="navbar">
			<view class="fixed">
				<!-- 状态栏 时间 电量 信号 -->
				<view :style="{height: navbarStatusHeight + 'px'}"></view>
				<!-- 胶囊按钮左侧位置 -->
				<view
					class="navbar-content"
					:style="{width: navBarWidth + 'px', height: navBarHeight + 'px'}"
				></view>
			</view>
			<!-- 设置占位 将微信小程序的状态栏高度预留出来 -->
			<!-- <view :style="{height:navbarStatusHeight+navBarHeight+'px' }"></view> -->
		</view>
		<view class="conten_block">
			<view class="logo_top">
				<view class="img">
					<image
						mode="aspectFill"
						class="user_img"
						v-if="store.state.userInfo.avatar"
						:src="store.state.userInfo.avatar"
						@click="lookPic(store.state.userInfo.avatar)"
					/>
					<uni-icons
						size="100"
						color="#007cff"
						type="contact"
						v-else
					></uni-icons>
				</view>
				<view class="user_inf">
					<view class="user_name">
						<view class="name">
							{{ store.state.userInfo.name }}
						</view>
						<view class="edit" @click="goEdit">编辑资料</view>
					</view>
					<view class="phone_tip">
						{{ store.state.userInfo.phone }}
					</view>
				</view>
			</view>
			<uni-list :border="false">
				<uni-list-item
					title="绑定手机"
					showArrow
					thumb="/static/network/user/phone.svg"
					@click="goAcl"
					link
					thumb-size="sm"
					:rightText="store.getters.setProcessingTel"
				/>
				<uni-list-item
					title="切换角色"
					:rightText="store.state.userInfo.network"
					showArrow
					@click="changeRole"
					link
					thumb="/static/network/user/role.svg"
					thumb-size="sm"
				/>
				<uni-list-item
					title="选择服务区域"
					showArrow
					@click="serviceArea"
					clickable
					thumb="/static/network/user/service.svg"
					thumb-size="sm"
				/>
				<uni-list-item
					title="创建服务商"
					showArrow
					@click="createNetwork"
					clickable
					thumb="/static/network/user/net_ing.svg"
					thumb-size="sm"
				/>
				<uni-list-item
					title="加入服务商"
					showArrow
					@click="addNetwork"
					clickable
					thumb="/static/network/user/add_net.svg"
					thumb-size="sm"
				/>
				<uni-list-item
					title="修改密码"
					showArrow
					@click="gochangePwd"
					link
					thumb="/static/network/user/change_pwd.svg"
					thumb-size="sm"
				/>
				<uni-list-item
					title="地址库"
					showArrow
					@click="bmcAddress"
					link
					thumb="/static/network/user/address.svg"
					thumb-size="sm"
				/>
				<view class="cancel_btn">
					<uni-list-item
						title="注销账号"
						showArrow
						@click="goCancel"
						link
						:show-extra-icon="true"
						:extraIcon="{color: '#007cff', size: '25', type: 'person'}"
					/>
				</view>
				<uni-list-item
					title="退出登录"
					showArrow
					@click="onLogout"
					link
					thumb="/static/network/user/icon_exit.svg"
					thumb-size="sm"
				/>
			</uni-list>
			<service-agreement-privacy-policy></service-agreement-privacy-policy>
		</view>
		<!-- 退出登录弹窗 -->
		<uni-popup ref="logoutDialog" type="dialog">
			<uni-popup-dialog
				cancelText="否"
				confirmText="是"
				title="通知"
				content="是否退出登录?"
				@confirm="dialogConfirm"
				@close="dialogClose"
			></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script setup lang="ts">
	import {ref, onMounted, reactive, watch} from 'vue';
	import store from '@/store_network/index.js';
	import {
		onReachBottom,
		onPullDownRefresh,
		onUnload,
		onLaunch,
		onLoad,
	} from '@dcloudio/uni-app';
	import apiLogin from '@/util/network_api/login.js';
	import NavTabbar from '@/components/u-network/nav-tabbar.vue';
	import ServiceAgreementPrivacyPolicy from '@/components/service-agreement-privacy-policy/ServiceAgreementPrivacyPolicy.vue'
	
	onLoad(async () => {
		//显示加载框
		uni.showLoading({
			title: '加载中',
		});
		// 获取用户信息
		await store.dispatch('getUpdataUser');
		// //隐藏加载框
		uni.hideLoading();
	});
	const logoutDialog = ref();
	const navbarStatusHeight = ref(0);
	const navBarHeight = ref(0);
	const navBarWidth = ref(375);
	onMounted(() => {
		const info = uni.getSystemInfoSync();
		navbarStatusHeight.value = info.statusBarHeight;
		// 根据微信小程序的右上侧的胶囊样式 设置导航栏内容的高度
		// 条件编译 以下三个不支持胶囊样式
		// #ifndef H5 || APP-PLUS || MP-ALIPAY
		const menuInfo = uni.getMenuButtonBoundingClientRect();
		// 导航栏内容的高度 = (胶囊底部的高度 - 状态栏的高度) + (胶囊顶部的高度 - 状态栏的高度)
		navBarHeight.value =
			menuInfo.bottom -
			info.statusBarHeight +
			(menuInfo.top - info.statusBarHeight);
		// 导航栏内容的宽度  除开胶囊按钮左侧的内容宽度
		navBarWidth.value = menuInfo.left;
		// #endif
	});
	// 预览图片
	const lookPic = (list) => {
		uni.previewImage({
			urls: [list],
		});
	};
	//退出
	const onLogout = () => {
		logoutDialog.value.open();
	};
	const goCancel = () => {
		uni.navigateTo({
			url: '/pages/pages_network/user/cancel',
		});
	};
	// 关闭弹窗
	const dialogClose = () => {
		logoutDialog.value.close();
	};
	// 确认退出登录
	const dialogConfirm = () => {
		uni.reLaunch({
			url: '/pages/pages_network/login/login',
		});
		apiLogin.logout().then((res) => {
			if (res.code == 20000) {
				uni.removeStorageSync('dd-access-network');
			}
		});
	};
	// 绑定手机
	const goAcl = () => {
		uni.navigateTo({
			url: '/pages/pages_network/user/acl',
		});
	};
	// 修改密码
	const gochangePwd = () => {
		uni.navigateTo({
			url: '/pages/pages_network/user/pwd',
		});
	};
	// 编辑信息
	const goEdit = () => {
		uni.navigateTo({
			url: '/pages/pages_network/user/edit',
		});
	};
	// 地址库
	const bmcAddress = () => {
		uni.navigateTo({
			url: '/pages/pages_network/user/address',
		});
	};
	// 切换角色
	const changeRole = () => {
		uni.navigateTo({
			url: '/pages/pages_network/login/role?isBack=false',
		});
	};
	// 加入服务商
	const addNetwork = () => {
		uni.navigateTo({
			url: '/pages/pages_network/user/add_network',
		});
	};
	// 创建服务商
	const createNetwork = () => {
		uni.navigateTo({
			url: '/pages/pages_network/user/create_network',
		});
	};
	// 选择服务区域
	const serviceArea = () => {
		uni.navigateTo({
			url: '/pages/pages_network/user/service_area',
		});
	};
</script>

<style lang="scss" scoped>
	.navbar {
		.fixed {
			// position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			width: 100%;
		}
	}

	.logo_top {
		display: flex;
		padding: 15% 30rpx 50rpx;

		.img {
			width: 110rpx;
			height: 110rpx;
			border-radius: 50%;
			margin-right: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			overflow: hidden;
			background-color: #fff;

			.user_img {
				width: 110rpx;
				height: 110rpx;
			}
		}

		.user_inf {
			display: flex;
			flex-direction: column;
			justify-content: center;

			.user_name {
				display: flex;
				align-items: center;

				.name {
					color: #000;
					font-size: 32rpx;
					margin-right: 14rpx;
				}

				.edit {
					font-size: 22rpx;
					color: #fff;
					border-radius: 21rpx;
					background: rgba(0, 124, 255, 1);
					height: 42rpx;
					width: 120rpx;
					text-align: center;
					line-height: 42rpx;
				}
			}

			.phone_tip {
				margin-top: 10rpx;
				color: rgba(85, 85, 85, 1);
				font-size: 28rpx;
			}
		}
	}

	.app_main {
		width: 100%;
		height: 100vh;
		background-image: url('@/static/network/login/bg_login.png');
		background-repeat: no-repeat;
		background-size: cover;
		background-position: top;
		position: relative;

		.conten_block {
			position: absolute;
			// margin-top: 12%;
			width: 100%;

			:deep(.uni-list) {
				// background-color: transparent !important;
				border-radius: 30rpx 30rpx 0 0;
				padding: 14rpx;

				.uni-list-item__container {
					padding: 12rpx 30rpx;
					padding-right: 0;
				}

				.cancel_btn {
					.uni-list-item__icon {
						padding-right: 8rpx;
						transform: translateX(-8rpx);
					}
				}

				.uni-list-item__content-title {
					font-size: 30rpx !important;
				}

				.uni-list-item {
					padding: 11rpx 0;
					background-color: transparent !important;
				}
			}
		}
	}
</style>
